﻿@{
    ViewBag.Title = "RoleEdit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using System.Globalization
@using RBS.Common
@using RBS.Core.Model
@model RBS.Core.Model.manager_role

<!--导航栏-->
<div class="location">
    <a href="RoleManage" class="back"><i></i><span>返回列表页</span></a>
    <a href="@Url.Action("Main", "Home")" class="home"><i></i><span>首页</span></a>
    <i class="arrow"></i>
    <a href="AdminUserManager"><span>管理员</span></a>
    <i class="arrow"></i>
    <a href="RoleManage"><span>管理角色</span></a>
    <i class="arrow"></i>
    <span>编辑角色</span>
</div>
<div class="line10"></div>
<!--/导航栏-->

<!--内容-->
<div class="content-tab-wrap">
    <div id="floatHead" class="content-tab">
        <div class="content-tab-ul-wrap">
            <ul>
                <li><a href="javascript:;" onclick="tabs(this);" class="selected">编辑角色信息</a></li>
            </ul>
        </div>
    </div>
</div>

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    @Html.HiddenFor(model => model.id)
           @Html.HiddenFor(model => model.is_sys)                          
    <div class="tab-content">
        <dl>
            <dt>角色类型</dt>
            <dd>
                <div class="rule-single-select"> 
                    @Html.DropDownListFor(model => model.role_type, (SelectList)ViewBag.roletype, htmlAttributes: new { datatype = "*", errormsg = "请选择角色类型！", sucmsg = " " })
                </div>
            </dd>
        </dl>
        <dl>
            <dt>角色名称</dt>
            <dd>
                @Html.TextBoxFor(model => model.role_name, null, new { @class = "input normal", datatype = "*1-100", sucmsg = " " })

                <span class="Validform_checktip">*角色中文名称，100字符内</span>
            </dd>
        </dl>
        <dl>
            <dt>管理权限</dt>
            <dd>
                <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="98%">
                    <thead>
                        <tr>
                            <th width="30%">导航名称</th>
                            <th>权限分配</th>
                            <th width="10%">全选</th>
                        </tr>
                    </thead>
                    <tbody>
                        @*    //@ViewBag.NavList*@
                        @foreach (SYS_Navigation person in ViewBag.NavList)
                        { 
                            <tr>
                                <td style="white-space: nowrap; word-break: break-all; overflow: hidden;">
                                    @{
                            string LitStyle = "<span style=\"display:inline-block;width:{0}px;\"></span>{1}{2}";
                            string LitImg1 = "<span class=\"folder-open\"></span>";
                            string LitImg2 = "<span class=\"folder-line\"></span>";
                            string LitFirst = "";
                            if (person.class_layer == 1)
                            {
                                LitFirst = LitImg1;
                            }
                            else
                            {
                                LitFirst = string.Format(LitStyle, (person.class_layer - 2) * 24, LitImg2, LitImg1);
                            } 
                                    }
                                    @Html.Raw(LitFirst)
                                    @person.title
                                </td>
                                <td>
                                    @foreach (KeyValuePair<string, string> kvp in Utils.ActionType())
                                    {
                                        var b = "";
                                        
                                        foreach (manager_role_value ctx in ViewBag.Nav)
                                        {
                                            if (ctx.nav_name == person.name)
                                            {
                                                if (ctx.action_type == kvp.Key)
                                                {
                                                    b = "checked";
                                                }
                                            } 
                                        }
                                        
                                        string[] actionTypeList = person.action_type.Split(',');
                                        foreach (var a in actionTypeList)
                                        {
                                            if (kvp.Key == a)
                                            {
                                        <input id="@person.name" type="checkbox" @b name="@person.name" value="@kvp.Key" class="cbllist" />
                                        <label for="@person.name">@kvp.Value</label>
                                            }
                                        }
                                    }
                                </td>
                                <td align="center">
                                    <input name="checkAll" type="checkbox" /></td>
                            </tr>
                        }
                    </tbody>
                </table>
            </dd>
        </dl>
    </div>
    <!--/内容--> 
    <!--工具栏-->
    <div class="page-footer">
        <div class="btn-list">
            <input type="submit" value="提交保存" class="btn" />
            <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick=" javascript: history.back(-1); " />
        </div>
        <div class="clear"></div>
    </div>
}

<script type="text/javascript">
    $(function () {

        //是否启用权限
        if ($("#role_type").find("option:selected").attr("value") == 1) {
            $(".border-table").find("input[type='checkbox']").prop("disabled", true);
        }
        $("#role_type").change(function () {
            if ($(this).find("option:selected").attr("value") == 1) {
                $(".border-table").find("input[type='checkbox']").prop("checked", false);
                $(".border-table").find("input[type='checkbox']").prop("disabled", true);
            } else {
                $(".border-table").find("input[type='checkbox']").prop("disabled", false);
            }
        });
        //权限全选
        $("input[name='checkAll']").click(function () {
            if ($(this).prop("checked") == true) {
                $(this).parent().siblings("td").find("input[type='checkbox']").prop("checked", true);
            } else {
                $(this).parent().siblings("td").find("input[type='checkbox']").prop("checked", false);
            }
        });
    });
</script>
<!--/工具栏-->
